﻿using System;
using Assets.Scripts.GtsScripts;
using UnityEngine;

namespace SteeringBehaviors
{
	// Token: 0x02000217 RID: 535
	public class Seek : SteerBehavior
	{
		// Token: 0x06000B44 RID: 2884 RVA: 0x0005EA49 File Offset: 0x0005CC49
		public Seek(MovementCharacter agent, IKinematic target, float separation = 0f, float duration = 0f) : base(agent, target)
		{
			this.Weight = 1.5f;
			this.startTime = Time.time;
			this.separationLimit = separation;
			this.duration = duration;
		}

		// Token: 0x06000B45 RID: 2885 RVA: 0x0005EA78 File Offset: 0x0005CC78
		public override SteeringOutput GetSteering()
		{
			TransformKinematic transformKinematic = this.target as TransformKinematic;
			if (transformKinematic)
			{
				Transform transform = transformKinematic.transform;
				if (!transform || (transform.GetComponent<Micro>() && transform.GetComponent<Micro>().isCrushed))
				{
					this.agent.Stop();
					return this.pSteering;
				}
			}
			this.pSteering.linear.x = this.target.position.x - this.agent.transform.position.x;
			this.pSteering.linear.y = 0f;
			this.pSteering.linear.z = this.target.position.z - this.agent.transform.position.z;
			this.pSteering.linear.Normalize();
			float maxAccel = this.agent.MaxAccel;
			SteeringOutput pSteering = this.pSteering;
			pSteering.linear.x = pSteering.linear.x * maxAccel;
			SteeringOutput pSteering2 = this.pSteering;
			pSteering2.linear.y = pSteering2.linear.y * maxAccel;
			SteeringOutput pSteering3 = this.pSteering;
			pSteering3.linear.z = pSteering3.linear.z * maxAccel;
			if (this.duration > 0f && Time.time > this.startTime + this.duration)
			{
				this.agent.Stop();
			}
			else if (this.separationLimit > -1f && this.target is TransformKinematic)
			{
				Vector3 vector = this.target.position - this.agent.transform.position;
				vector.y = 0f;
				float magnitude = vector.magnitude;
				GameObject gameObject = ((TransformKinematic)this.target).transform.gameObject;
				CapsuleCollider component = gameObject.GetComponent<CapsuleCollider>();
				if (!component)
				{
					Giantess component2 = gameObject.GetComponent<Giantess>();
					component = component2.GtsMovement.GetComponent<CapsuleCollider>();
				}
				CapsuleCollider component3 = this.agent.gameObject.GetComponent<CapsuleCollider>();
				float a = component3.radius * component3.transform.lossyScale.y;
				float b = component.radius * component.transform.lossyScale.y;
				float num = Mathf.Max(a, b);
				float num2 = Mathf.Min(a, b);
				float num3 = num;
				if (magnitude < num + num2)
				{
					num3 += num2;
				}
				float num4 = (magnitude - num - num2) / num3;
				if (num4 < this.separationLimit)
				{
					this.agent.Stop();
				}
			}
			return this.pSteering;
		}

		// Token: 0x04001055 RID: 4181
		private float startTime;

		// Token: 0x04001056 RID: 4182
		private float separationLimit;

		// Token: 0x04001057 RID: 4183
		private float duration;
	}
}
